<template>
    <div class="app-container">
        <el-row :gutter="24">
            <el-col :span="24" :xs="24">
                <el-form :model="queryParams" ref="queryRef" :inline="true" style="margin-left: 25px;">
                    <el-form-item label="使用单位" prop="usingUnityName">
                        <el-input v-model="queryParams.usingUnityName" placeholder="请输入" clearable style="width: 220px"
                            maxlength="30" @keyup.enter="handleQuery" />
                    </el-form-item>
                    <el-form-item label="设备代码" prop="registrationCode">
                        <el-input v-model="queryParams.registrationCode" placeholder="请输入" clearable style="width: 220px"
                            maxlength="30" @keyup.enter="handleQuery" />
                    </el-form-item>
                    <el-form-item style="margin-left: 0px;">
                        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-table v-loading="loading" :data="detectionList"
                    style="margin-top: 30px;margin-left: 10px;margin-right: 10px;width: calc(100% - 20px);">
                    <el-table-column type="index" width="50" label="序号" fixed="left" />
                    <el-table-column label="设备种类" align="center" prop="className" width="180px" />
                    <el-table-column label="设备类别" align="center" prop="categoryName" width="180px" />
                    <el-table-column label="设备品种" align="center" prop="varietyName" width="180px" />
                    <el-table-column label="注册代码" align="center" prop="registrationCode" width="220px" />
                    <el-table-column label="使用使用单位" align="center" prop="usingUnityName" width="220px" />
                    <el-table-column label="使用登记证号" align="center" prop="useRegistrationCode" width="220px" />
                    <el-table-column label="单位内编号" align="center" prop="unityIdentifier" width="180px" />
                    <el-table-column label="设备使用地址" align="center" prop="usingAddress" width="220px" />
                    <el-table-column label="下次检测日期" align="center" prop="downTime" width="180px" />
                    <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width"
                        width="120px">
                        <template #default="scope">
                            <el-button link type="success" @click="handleDetails(scope.row)">查看</el-button>
                            <el-button link type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
                    @pagination="getList" style="margin-right: 20px;" />
            </el-col>
        </el-row>

        <el-dialog v-model="dialogVisible" draggable title="设备信息" width="1000px">
            <el-tabs v-model="dialogTabActiveName" class="demo-tabs" @tab-click="handleClick">
                <el-tab-pane label="基础信息" name="base">
                    <DeviceBaseInfo :infoId="dialogInfo.id" :isCanEdit="isCanEdit"></DeviceBaseInfo>
                </el-tab-pane>
                <el-tab-pane label="参数信息" name="params">
                    <DeviceParamsInfo :infoId="dialogInfo.id" :isCanEdit="isCanEdit"></DeviceParamsInfo>
                </el-tab-pane>
            </el-tabs>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="submitEdit">确认</el-button>
                </span>
            </template>
        </el-dialog>
        <DeviceForm ref="formRef" @success="getList" />
    </div>
</template>
 
<script setup name="User">
import { apiGetDeviceList, apiGetDeviceDetails } from "@/api/device";
import DeviceBaseInfo from "@/components/DeviceBaseInfo";
import DeviceParamsInfo from "@/components/DeviceParamsInfo";
import DeviceForm from "./deviceForm.vue";
import { ref } from "vue";

const { proxy } = getCurrentInstance();

const detectionList = ref([]);
const loading = ref(false);
const total = ref(0);
const dialogInfo = ref({})
const dialogVisible = ref(false)
const isCanEdit = ref(false)
const dialogTabActiveName = ref('base')

const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
});

/** 查询列表 */
const getList = () => {
    loading.value = true;
    apiGetDeviceList(queryParams.value).then(res => {
        loading.value = false;
        if (res.data) {
            detectionList.value = res.data.records;
            total.value = res.data.total;
        } else {
            detectionList.value = [];
            total.value = 0;
        }
    }).catch(err => {
        loading.value = false;
        detectionList.value = [];
        total.value = 0;
    });
};

getList();

const getCs = () => {
    console.log(111);
}

/** 搜索按钮操作 */
const handleQuery = () => {
    queryParams.value.pageNum = 1;
    getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
    proxy.resetForm("queryRef");
    handleQuery();
};

/** 编辑 */
const formRef = ref()
const handleEdit = (row) => {
    formRef.value.open(row.id)
};

//详情
const handleDetails = (row) => {
    loading.value = true;
    apiGetDeviceDetails(row.id).then(res => {
        loading.value = false;
        if (res.data) {
            dialogInfo.value = res.data
            isCanEdit.value = false
            dialogVisible.value = true
        }
    }).catch(err => {
        loading.value = false;
    });
};

const submitEdit = (row) => {
    proxy.$modal.msgSuccess("操作成功");
};

const handleDel = (row) => {
    proxy.$modal.confirm('是否确认删除该数据项？').then(function () {
        return delUser(row.userId || '');
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("操作成功");
    }).catch(() => { });
};

</script>
 

<style lang="scss" scoped>
.dialog-item-title {
    color: #000;
    font-size: 17px;
    padding-left: 10px;
    margin: 0 20px;
    border-left: 4px #00BFFF solid;
}

.now-select-txt {
    font-size: 15px;
    color: #fff;
    background: #00BFFF;
    padding: 10px 20px;
    border-radius: 10px 10px 0 0;

    span {
        font-size: 20px;
        font-weight: bold;
        margin: 0 10px;
    }

    div {
        cursor: pointer;
        margin-left: 30px;
        font-weight: bold;
    }
}

.tabs-div {
    max-height: 59vh;
    overflow-y: auto;
}
</style>

<style lang="scss">
.el-dialog__body {
    padding-top: 0px !important;
    padding-bottom: 10px !important;
}
</style>